package com.study.scala.collections.list

object TestList3 {
  def main(args: Array[String]): Unit = {
    //
    //    val list1=List(1,2,3,4);
    //    val list2=List(5,9,3,4);
    //    println(sum(list1))
    //    println( list1.foldRight(1)(_*_))
    //    println(list2.sortWith(_ < _))
    //    println(list2.sorted)

    val worker1 = new Worker("wangyj", 10);
    val worker2 = new Worker("zhaosc", 9);
    val worker3 = new Worker("gongxp", 12);

    val listWorker = List(worker1, worker2, worker3);
    //    listWorker.sortWith((w1,w2)=>{ w1.getSalary()>w2.getSalary()}).foreach(println)
    //    listWorker.sortBy(f=>f.getSalary());
  //  listWorker.sorted(KeyOrdering).foreach(println _)
    
    val worker21 = new Worker2("wangyj", 10);
    val worker22 = new Worker2("zhaosc", 9);
    val worker23 = new Worker2("gongxp", 12);
    
   val listWorker2 = List(worker21, worker22, worker23);
   
 listWorker2.foreach(println _)
  }
  implicit val KeyOrdering = new Ordering[Worker] {
    override def compare(x: Worker, y: Worker): Int = {
      x.getSalary() - y.getSalary()
    }
  }
  def sum(list: List[Int]): Int = {
    (0 /: list)(_ + _)
  }

}